﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace WebUI.Pages
{
    public partial class mgrTeams : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get credentials
            UserController usrController = new UserController();
            int secUsuario = usrController.GetUserID(User.Identity.Name);
            int secTeam = usrController.GetUserTeamID(secUsuario);

            if (secTeam != 9)
            {
                Response.Redirect("../Pages/403.aspx");
            }             
            if (!this.IsPostBack)
            {
                TeamController tmController = new TeamController();
                rpTeams.DataSource = tmController.GetTeams();
                rpTeams.DataBind();

                ddlGestor.DataSource = usrController.GetTeamUsers(9);
                ddlGestor.DataTextField = "Nome";
                ddlGestor.DataValueField = "idUsuario";
            }
        }

        protected void rpTeams_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Response.Redirect("../Pages/editTeam.aspx?id=" + e.CommandArgument.ToString());
        }

        protected void cmdNovo_Click(object sender, EventArgs e)
        {
            TeamController tmController = new TeamController();
            tmController.NewTeam(Convert.ToInt32(ddlGestor.SelectedValue),txtNome.Text);
            Response.Redirect("../Pages/mgrTeams.aspx");
        }
    }
}